<template>
    <!-- <div id="phone or mail" style="max-width: 400px;">
        <el-select v-model="value" placeholder="请选择手机或邮箱" style="max-width: 100px;text-align:center;display: inline;">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
        </el-select>
        <br/>
        <el-input placeholder="请输入" v-model="input10" clearable style="max-width:300px;text-align:center;display: inline;">
        </el-input>
        <br/>
        <br/> -->
        <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="100px" class="demo-ruleForm">
        <el-select v-model="value" placeholder="请选择手机或邮箱" style="max-width: 100px;text-align:center;display: inline;">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
        </el-select>
        <el-form-item label="请输入" prop="signUpId">
            <el-input v-model="ruleForm2.signUpId"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="checkCode">
            <el-input v-model="ruleForm2.checkCode"></el-input>
        </el-form-item>
    </el-form>
    <!-- </div> -->
</template>

<script>
    export default {
        data() {
            var checkId = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('用户不能为空'));
                }
            };
            var checkCode = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('验证码不能为空'));
                }
            };
            var validatePass = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入验证码'));
                } else {
                    if (this.ruleForm2.checkPass !== '') {
                        this.$refs.ruleForm2.validateField('checkPass');
                    }
                    callback();
                }
            };
            var validatePass2 = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请再次输入密码'));
                } else if (value !== this.ruleForm2.pass) {
                    callback(new Error('两次输入密码不一致!'));
                } else {
                    callback();
                }
            };
            return {
                // 选择框的内容
                options: [{
                    value: '选项1',
                    label: '手机'
                }, {
                    value: '选项2',
                    label: '邮箱'
                }],
                value: '',
                // 表单的数据和方法
                ruleForm2: {
                    pass: '',
                    checkPass: '',
                    id: ''
                },
                rules2: {
                    pass: [{
                        validator: validatePass,
                        trigger: 'blur'
                    }],
                    checkPass: [{
                        validator: validatePass2,
                        trigger: 'blur'
                    }],
                    id: [{
                        validator: checkId,
                        trigger: 'blur'
                    }]
                }
            };
        }
    }
</script>

<style>
    #phone or mail {
        display: -webkit-flex;
        display: flex;
        -webkit-justify-content: center;
        justify-content: center;
    }
</style>
